package com.example.myqq;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    private EditText etUsername, etPassword, etVerifyCode;
    private Button btnLogin, btnGetVerifyCode;
    private TextView tvRegister;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        etUsername = findViewById(R.id.et_account);
        etPassword = findViewById(R.id.et_password);

        btnLogin = findViewById(R.id.btn_login);

        tvRegister = findViewById(R.id.tv_register);


        btnLogin.setOnClickListener(v -> {
            String username = etUsername.getText().toString().trim();
            String password = etPassword.getText().toString().trim();
            String verifyCode = etVerifyCode.getText().toString().trim();

            if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password) || TextUtils.isEmpty(verifyCode)) {
                Toast.makeText(this, "请填写所有字段", Toast.LENGTH_SHORT).show();
                return;
            }

            if (username.equals("test") && password.equals("123456") && verifyCode.equals("1234")) {
                Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();

                startActivity(new Intent(this, MainActivity.class)); // 假设 MainActivity 是主页
                finish();
            } else {
                Toast.makeText(this, "用户名、密码或验证码错误", Toast.LENGTH_SHORT).show();
            }
        });


        btnGetVerifyCode.setOnClickListener(v -> {
            String phone = etUsername.getText().toString().trim();
            if (TextUtils.isEmpty(phone)) {
                Toast.makeText(this, "请输入手机号", Toast.LENGTH_SHORT).show();
                return;
            }
            Toast.makeText(this, "验证码已发送到 " + phone, Toast.LENGTH_SHORT).show();

        });


        tvRegister.setOnClickListener(v -> {
            startActivity(new Intent(this, RegisterActivity.class));
        });
    }
}